<template>
  <div class="app-container">
    <!--控制组件-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          @click="handleSearch"
          size="mini"
          >查询</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          :disabled="selection.length < 1"
          icon="el-icon-circle-check"
          size="mini"
          @click="printCheck"
          v-hasPermi="['putStorage:putStorageFinish:post']"
        >
          批准打印
        </el-button>
      </el-col>
    </el-row>
    <!--头表Tab-->
    <el-table
      @scrollBottom="load"
      highlight-current-row
      border
      stripe
      v-loading="loading"
      :data="rwmMsrtList"
      @row-click="clickRwm"
      @selection-change="handleSelectionChange"
      :cell-style="iCellStyle"
      :height="tableH"
      :header-cell-style="{ 'text-align': 'center' }"
    >
      <el-table-column
        fixed="left"
        type="selection"
        width="55"
        align="center"
      />
      <el-table-column
        label="入库单号"
        :show-overflow-tooltip="true"
        width="135"
        align="center"
        prop="rwmDjbh"
      />
      <el-table-column
        label="入库日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rwmRkrq"
        width="150"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rwmRkrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="入库类型"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rwmType"
      >
        <template #default="scope">
          <dict-tag :options="psTypeOptions" :value="scope.row.rwmType" />
        </template>
      </el-table-column>
      <el-table-column
        label="入库仓库"
        class-name="rkck"
        :show-overflow-tooltip="true"
        width="140"
        align="center"
        prop="rwmCkdm"
      >
        <template #default="scope">
          <dict-tag :options="allStorageOptions" :value="scope.row.rwmCkdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="供应商"
        :show-overflow-tooltip="true"
        width="140"
        align="center"
        prop="rwmCsdm"
      >
        <template #default="scope">
          <dict-tag :options="allCsOptions" :value="scope.row.rwmCsdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="收货单号"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rwmShdh"
      />
      <el-table-column
        label="检验结果"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rwmJyjg"
      >
        <template #default="scope">
          <dict-tag :options="jyjgDict" :value="scope.row.rwmJyjg" />
        </template>
      </el-table-column>
      <el-table-column
        label="备注"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rwmDesc"
      />
      <el-table-column
        label="建立人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rwmJlry"
      />
      <el-table-column
        label="建立日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rwmJlrq"
        width="150"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rwmJlrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="检验人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rwmJyry"
      />
      <el-table-column
        label="检验日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rwmJyrq"
        width="150"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rwmJyrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="过账人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rwmGzry"
      />
      <el-table-column
        label="过账日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rwmGzrq"
        width="150"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rwmGzrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="来料入库单"
        align="center"
        width="100"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            size="mini"
            type="danger"
            @click="printCheck(scope.row)"
            v-hasPermi="['putStorage:putStorageFinish:print']"
            >批准打印</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!--子表Tab-->
    <el-tabs v-model="activeTab">
      <el-tab-pane label="入库明细" name="first">
        <el-table
          border
          stripe
          :height="tableHChild"
          :data="rwdDetList"
          :header-cell-style="{ 'text-align': 'center' }"
          :cell-style="iCellStyleC"
        >
          <el-table-column label="#" type="index" width="55" align="center" />
          <el-table-column
            label="客户编号"
            align="center"
            prop="itmCustwldm"
            fixed="left"
          />
          <el-table-column
            label="来源单号"
            align="center"
            width="135"
            show-overflow-tooltip
            prop="rwdCgdh"
          />
          <el-table-column
            label="物料代码"
            width="135"
            show-overflow-tooltip
            align="center"
            prop="rwdWldm"
          />
          <el-table-column
            label="规格描述"
            width="330"
            show-overflow-tooltip
            prop="itmPmgg"
          />
          <el-table-column
            label="单价"
            :show-overflow-tooltip="true"
            align="center"
            width="60"
            prop="rwdMoney"
          />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            width="60"
            align="center"
            prop="itmDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="存放位置"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdCwdm"
          >
            <template #default="scope">
              <dict-tag :options="allCwOptions" :value="scope.row.rwdCwdm" />
            </template>
          </el-table-column>
          <el-table-column
            label="最小包装"
            align="center"
            prop="itmMinbz"
            width="80"
          />
          <el-table-column
            label="包装数量"
            align="center"
            prop="rwdBzsl"
            width="80"
          />
          <el-table-column
            label="申请数量"
            align="center"
            prop="rwdSqsl"
            width="80"
          />
          <el-table-column
            label="允收数量"
            align="center"
            prop="rwdOksl"
            width="80"
          />
          <el-table-column
            label="拒收数量"
            align="center"
            prop="rwdNgsl"
            width="80"
          />
          <el-table-column
            label="入库数量"
            align="center"
            prop="rwdRksl"
            width="80"
          />
          <el-table-column
            label="检验结果"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdJyjg"
          >
            <template #default="scope">
              <dict-tag :options="jyjgDict" :value="scope.row.rwdJyjg" />
            </template>
          </el-table-column>
          <el-table-column label="结果描述" align="center" prop="rwdJydecs" />
          <el-table-column
            label="检验人员"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdJyry"
          />
          <el-table-column
            label="检验日期"
            :show-overflow-tooltip="true"
            align="center"
            prop="rwdJyrq"
            width="150"
          >
            <template #default="scope">
              <span>{{ parseTime(scope.row.rwdJyrq, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="入库人员"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rwdRkry"
          />
          <el-table-column
            label="入库日期"
            :show-overflow-tooltip="true"
            align="center"
            prop="rwdRkrq"
            width="150"
          >
            <template #default="scope">
              <span>{{ parseTime(scope.row.rwdRkrq, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="入库统计" name="second">
        <el-table
          border
          stripe
          :header-cell-style="{ 'text-align': 'center' }"
          :data="rwdDetTotal"
        >
          <el-table-column
            label="#"
            type="index"
            min-width="5%"
            align="center"
            fixed="left"
          />
          <el-table-column
            label="客户编号"
            align="center"
            min-width="20%"
            prop="itmCustwldm"
          />
          <el-table-column
            label="物料代码"
            align="center"
            min-width="20%"
            prop="rwdWldm"
          />
          <el-table-column label="规格描述" prop="itmPmgg" min-width="40%" />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            min-width="10%"
            align="center"
            prop="itmDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="最小包装"
            align="center"
            prop="itmMinbz"
            min-width="10%"
          />
          <el-table-column
            label="包装数量"
            align="center"
            prop="rwdBzsl"
            min-width="10%"
          />
          <el-table-column
            label="申请数量"
            align="center"
            prop="rwdSqsl"
            min-width="10%"
          />
          <el-table-column
            label="允收数量"
            align="center"
            prop="rwdOksl"
            min-width="10%"
          />
          <el-table-column
            label="拒收数量"
            align="center"
            prop="rwdNgsl"
            min-width="10%"
          />
          <el-table-column
            label="入库数量"
            align="center"
            prop="rwdRksl"
            min-width="10%"
          />
        </el-table>
      </el-tab-pane>
    </el-tabs>

    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="750px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <el-col :span="12">
          <el-form-item label="开单日期">
            <el-date-picker
              v-model="daterangeRwmJlrq"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions"
              :default-time="['00:00:00', '23:59:59']"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库单号" prop="rwmDjbh">
            <el-input
              v-model="queryParams.rwmDjbh"
              placeholder="请输入入库单号"
              clearable
              style="width: 240px"
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="厂商代码" prop="rwmCsdm">
            <el-select
              v-model="queryParams.rwmCsdm"
              style="width: 240px"
              clearable
              filterable
              placeholder="请选择厂商代码"
            >
              <el-option
                v-for="item in csOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库仓库" prop="rwmCkdm">
            <el-select
              v-model="queryParams.rwmCkdm"
              style="width: 240px"
              clearable
              filterable
              placeholder="请选择仓库"
            >
              <el-option
                v-for="item in storageOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="综合查询" prop="totalOrder">
            <el-input
              type="textarea"
              v-model="totalOrder"
              clearable
              style="width: 600px"
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <br />
        <el-col :span="24" style="text-align: center">
          <el-form-item prop="rwmDjbh">
            <RadioGroup v-model="queryParams.rwmZtbz">
              <Radio label="7">未过账</Radio>
              <Radio label="8">已过账</Radio>
              <Radio label="9">全部</Radio>
            </RadioGroup>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  listPutStorageAdd,
  postRwdDet,
  exportPutStorageAdd,
  getCs,
  rwmPost,
  allPutStorage,
  updatePutStorageAdd,
  checkPomPod,
  getAllCs,
  print,
  exportRwm,
  applyDy,
  getRwmByApplyDy,
  checkDy,
} from "@/api/putStorage/putStorageAdd";
import { getPstorageType } from "@/api/repertory/putstorage";
import { getAll, getstorageType } from "@/api/repertory/Storage";
import {
  getRwdDet,
  listRwdDet,
  updateRwdDet,
  clickAllJy,
} from "@/api/putStorage/RwdDet";
import { printOrder } from "@/utils/ruoyi";

export default {
  name: "PutStoragePrint",
  data() {
    return {
      tableH:
        document.body.clientHeight > 900
          ? document.body.clientHeight / 2 - 96
          : document.body.clientHeight / 2 - 95,
      tableHChild: document.body.clientHeight / 2 - 150,
      // 遮罩层
      loading: true,
      printDiag: true,
      // 导出遮罩层
      exportLoading: false,
      loadingChild: false,
      //默认子表
      activeTab: "first",
      // 选中数组
      selection: [],
      selectionIds: [],
      printDjbh: null,
      printGzry: null,
      printType: null,
      printRkrq: null,
      printCkdm: null,
      printCsmc: null,
      // 功能按钮隐藏/显示
      type1: true, //允收/特采/撤回开单/拒收/一键检验
      rwmZtbzc: "0",
      //单击事件选中的单据
      clickRwmMstr: {
        rwmDjbh: "",
      },
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      //检验结果
      confirmOpen: false,
      check_back: false,
      check_all: false,
      check_permit: false,
      //过账日期
      Gzrq: new Date(),
      //检验结果单选组
      jyjgOptions: [
        {
          label: "允收",
          value: "OK",
        },
        {
          label: "拒收",
          value: "NG",
        },
        {
          label: "特采",
          value: "TC",
        },
      ],

      // 总条数
      total: 0,
      // 来料进货入库表格数据
      rwmMsrtList: [],
      // 入库详细表数据
      rwdDetList: [],
      rwdDetTotal: [],
      //入库类型
      psTypeOptions: [],
      //单位字典
      unitFlagOptions: [],
      //存储厂商
      csOptions: [],
      allCsOptions: [],
      //存放储位
      allCwOptions: [],
      //存储仓库
      storageOptions: [],

      //所有仓库
      allStorageOptions: [],
      //检验结果字典
      jyjgDict: [
        {
          dictLabel: "允收",
          dictValue: "OK",
          listClass: "default",
        },
        {
          dictLabel: "拒收",
          dictValue: "NG",
          listClass: "default",
        },
        {
          dictLabel: "特采",
          dictValue: "TC",
          listClass: "default",
        },
      ],
      // 弹出层标题
      title: "",
      // 建立日期时间范围
      daterangeRwmJlrq: [
        new Date(new Date().getFullYear(), new Date().getMonth() - 1),
        this.$moment().endOf("month").toDate(),
      ],
      totalOrder: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        rwmDjbh: null,
        rwmZtbz: "9",
        rwmJlrq: null,
      },
      // 表单参数
      form: {},
      formRwd: {},
      // 表单校验
      rules: {},
      //日期初始化
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  created() {
    this.getList();
    getPstorageType(0).then((response) => {
      this.psTypeOptions = response.data;
      for (let i of this.psTypeOptions) {
        i.listClass = "default";
      }
    });
    this.getDicts("sys_unit").then((response) => {
      this.unitFlagOptions = response.data;
    });

    getAll().then((response) => {
      this.allCwOptions = response.data;

      for (let item2 of this.allCwOptions) {
        item2.dictLabel = item2.storageDefaultstorage;
        item2.listClass = "default";
        item2.dictValue = item2.storageId + "";
      }
    });

    getAll().then((response) => {
      this.allStorageOptions = response.data;

      for (let item2 of this.allStorageOptions) {
        item2.dictLabel = item2.storageName;
        item2.listClass = "default";
        item2.dictValue = item2.storageId + "";
      }
    });

    getCs().then((response) => {
      this.csOptions = response.data;
      for (let item of this.csOptions) {
        item.dictLabel = item.csmCs;
        item.listClass = "default";
        item.dictValue = item.csmCsdm;
      }
    });

    getstorageType("0").then((response) => {
      this.storageOptions = response.data;
      for (let item of this.storageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });

    getAllCs().then((response) => {
      this.allCsOptions = response.data;
      for (let item of this.allCsOptions) {
        item.dictLabel = item.csmCs;
        item.listClass = "default";
        item.dictValue = item.csmCsdm;
      }
    });
  },
  methods: {
    /** 查询来料进货入库开单列表 */
    getList(row) {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeRwmJlrq && "" != this.daterangeRwmJlrq) {
        this.queryParams.params["beginRwmJlrq"] = this.moment(
          this.daterangeRwmJlrq[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["endRwmJlrq"] = this.moment(
          this.daterangeRwmJlrq[1]
        ).format("YYYY-MM-DD HH:mm:ss");
      }
      if (null != this.totalOrder && "" != this.totalOrder) {
        this.queryParams.params["totalOrder"] = this.totalOrder;
      }
      this.queryParams.pageNum = 1;
      getRwmByApplyDy(this.queryParams).then((response) => {
        this.rwmMsrtList = [];
        this.rwdDetList = [];
        this.rwdDetTotal = [];
        this.rwmMsrtList = this.rwmMsrtList.concat(response.rows);
        this.total = response.total;
        this.loading = false;
        if (row != null) {
          this.clickRwm(row);
        } else if (this.rwmMsrtList != null && this.rwmMsrtList.length > 0) {
          this.clickRwm(this.rwmMsrtList[0]);
        }
      });
    },

    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        this.queryParams.pageSize = 20;
        this.queryParams.pageNum++;
        getRwmByApplyDy(this.queryParams).then((response) => {
          this.rwmMsrtList = this.rwmMsrtList.concat(response.rows);
          this.total = response.total;
          this.loading = false;
        });
      }
      return 0;
    },
    // 取消按钮
    cancel() {
      this.openSearch = false;
      this.confirmOpen = false;
      this.printDiag = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        rwmId: null,
        rwmDjbh: null,
        rwmRkrq: null,
        rwmType: null,
        rwmCsdm: null,
        rwmCkdm: null,
        rwmShdh: null,
        rwmDesc: null,
        rwmTjflag: null,
        rwmNgdesc: null,
        rwmZtbz: "0",
        rwmJyjg: null,
        rwmJlry: null,
        rwmJlrq: null,
        rwmJyry: null,
        rwmJyrq: null,
        rwmGzry: null,
        rwmGzrq: null,
      };
      this.formRwd = {
        rwdDjbh: null,
        rwdCgdh: null,
        rwdWldm: null,
        itmPmgg: null,
        rwdCwdm: null,
        rwdOksl: 0,
        rwdBzsl: null,
        itmMinbz: null,
        rwdRksl: 0,
        rwdJydesc: null,
      };
      this.resetForm("form");
      this.resetForm("formRwd");
    },
    /** 颜色事件 */
    iCellStyle: function ({ row, column, rowIndex, columnIndex }) {
      //提交
      if (row.rwmZtbz == "1" && row.rwmTjflag == "1") {
        return "color:#0fac09";
      }
      //通过
      else if (row.rwmZtbz == "2" && row.rwmTjflag == "1") {
        return "color:#0323af";
      }
      //检验
      else if (row.rwmZtbz == "6" && row.rwmTjflag == "1") {
        return "color:#bb0331";
      }
      if (row.rwmZtbz == "6" && row.rwdJyjg != "") {
        return "color:#bb0331";
      }
    },
    iCellStyleC: function ({ row, column, rowIndex, columnIndex }) {
      if (row.rwdRkry) {
        return "color:#bb0331";
      }
    },
    printData(row) {
      exportRwm(row.rwmDjbh).then((res) => {
        this.printPage(row);
      });
    },
    printPage(row) {
      if (this.loadingChild) {
        setTimeout(this.printPage, 100);
      } else {
        this.$refs.printPage.print();
        row.rwmDyflag = 1;
      }
    },
    printHandle(a) {
      if (a.rwmZtbz != "6") {
        this.$confirm("当前单据还未过账，是否过账并执行打印？", "温馨提醒", {
          confirmButtonText: "过账并打印",
          cancelButtonText: "取消",
          type: "info",
        }).then((res) => {
          this.clickRwmMstr = a;
          if (this.is_empty()) {
            this.$Modal.warning({
              title: "提示",
              content: "存在未确认入库数量的材料，不允许此操作",
            });
          } else {
            const data = {
              rwmDjbh: this.clickRwmMstr.rwmDjbh,
              rwmId: this.clickRwmMstr.rwmId,
              rwmZtbz: 6,
              rwmGzry: this.$store.state.user.nickName,
              rwmGzrq: new Date(),
            };
            rwmPost(data).then((res) => {
              this.msgSuccess("过账成功~");
              this.clickRwmMstr = {};
              this.queryParams.pageNum = 1;
              this.rwmMsrtList = [];
              this.getList();
              this.printData(a);
              // printOrder('/putStorage/putStorageAdd/exportIncomingGoodsTemplate', a, '来料入库单据')
            });
          }
        });
        return;
      }
      this.printData(a);
      // printOrder('/putStorage/putStorageAdd/exportIncomingGoodsTemplate', a, '来料入库单据')
    },
    printCheck(row) {
      //申请打印
      const ids = row.rwmDjbh ? [row.rwmDjbh] : this.selectionIds;
      console.log(ids);
      checkDy(ids).then((res) => {
        this.msgSuccess("已批准，允许再次打印！");
        this.getList();
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.rwmMsrtList = [];
      this.getList();
      this.openSearch = false;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeRwmJlrq = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleSearch() {
      this.reset();
      this.title = "品管检验查询";
      this.openSearch = true;
    },
    /** 单击查看详细数据 */
    clickRwm(row) {
      //获得当前单据的状态
      this.type1 = !(row != null && row.rwmZtbz == "2" && row.rwmTjflag == "1");
      if (row != null) {
        this.rwmZtbzc = row.rwmZtbz;
      }
      this.clickRwmMstr = row;
      console.log(this.clickRwmMstr);
      //获得选中的详细数据
      this.getRwdDetList(row.rwmDjbh);
    },
    /** 获取RwdDet 数据*/
    getRwdDetList(rwdDjbh) {
      this.rwdDetList = [];
      this.rwdDetTotal = [];
      this.loadingChild = true;
      if (rwdDjbh != null && rwdDjbh != "") {
        const query = { rwdDjbh: rwdDjbh };
        listRwdDet(query).then((response) => {
          this.rwdDetList = response.data.detail;
          this.rwdDetTotal = response.data.total;
          this.loadingChild = false;
        });
      }
    },
    is_empty() {
      if (this.rwdDetList.length > 0) {
        for (let i of this.rwdDetList) {
          console.log(this.rwdDetList);
          if (i.rwdRkry === null && i.rwdRkrq == null) return true;
        }
        return false;
      } else {
        return true;
      }
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectionIds = selection.map((item) => item.rwmDjbh);
      this.selection = selection;
    },

    handleInput(a) {
      if (a > this.formRwd.rwdOksl) {
        this.formRwd.rwdRksl = this.formRwd.rwdOksl;
      }
    },
    //入库确认事件
    rkSubmit() {
      const data = {
        rwdDjbh: this.formRwd.rwdDjbh,
        rwdCgdh: this.formRwd.rwdCgdh,
        rwdWldm: this.formRwd.rwdWldm,
        rwdRksl: this.formRwd.rwdRksl,
      };
      postRwdDet(data).then((res) => {
        if (res.code == 200) {
          this.msgSuccess("入库成功~");
          this.formRwd = {};
          this.confirmOpen = false;
          this.getRwdDetList(this.clickRwmMstr.rwmDjbh);
        } else {
          this.msgSuccess("入库失败~");
        }
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有来料进货入库开单数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportPutStorageAdd(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped></style>
